//
//  AiViewController.m
//  Ai
//
//  Created by 杜超男 on 2019/3/6.
//  Copyright © 2019年 杜超男. All rights reserved.
//

#import "AiViewController.h"
#import "XLSlideSwitch.h"//滑动滚动第三方
#import "ManagementCenterViewController.h"//管理中心
#import "FaceFiltratePushViewController.h"//表情筛选推送
#import "ClassLanguageCollectViewController.h"//班级语言汇总
#import "Masonry.h"
#import "CusNavigationController.h"
@interface AiViewController ()<XLSlideSwitchDelegate , UITableViewDelegate , UITableViewDataSource>
{
    UIButton *DropDownBtn;//下拉的按钮
    UIView *KingdergartenSele;//选择幼儿园的view;
    UIView *bigview;
}
@property (nonatomic , strong)XLSlideSwitch *ScrollView;///滚动视图
@property (nonatomic , strong)UILabel *HeaderText;
@property (nonatomic , strong)UITableView *tableView;
@property (nonatomic , strong)NSMutableArray *DataSoure;
@end

@implementation AiViewController
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    CusNavigationController *cus = [CusNavigationController new];
//    cus.navigationController.navigationBar.hidden = YES;
    self.navigationController.navigationBar.hidden = YES;
    self.tabBarController.tabBar.hidden = NO;
}
- (void)viewWillDisappear:(BOOL)animated{
//    self.tabBarController.tabBar.hidden = NO;
//    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
//    [self.navigationController.navigationBar setShadowImage:nil];
}
-(void)viewDidAppear:(BOOL)animated{
//    self.tabBarController.tabBar.hidden = NO;
}
-(void)viewDidDisappear:(BOOL)animated{
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.DataSoure = [NSMutableArray arrayWithObjects:@"好好学习幼儿园人工智能系统好好学习幼……" , @"好好学习幼儿园人工智能系统好好学习幼……",@"好好学习幼儿园人工智能系统好好学习幼……",@"好好学习幼儿园人工智能系统好好学习幼……",@"好好学习幼儿园人工智能系统好好学习幼……", nil];
//    [self.DataSoure addObject:@[@"好好学习幼儿园人工智能系统好好学习幼……" , @"好好学习幼儿园人工智能系统好好学习幼……"]];
    // Do any additional setup after loading the view.
    UITabBar *tabbar = [UITabBar appearance];
    //tabBar.translucent
    tabbar.translucent = NO;
    self.view.backgroundColor = [UIColor whiteColor];
    UIView *backgroundColorView =  [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 500)];
    backgroundColorView.backgroundColor = [UIColor colorWithRed:98/256.0 green:187/256.0 blue:81/256.0 alpha:1];
    [self.view addSubview:backgroundColorView];
    
    
    [self.view addSubview:self.HeaderText];
    [_HeaderText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view.mas_safeAreaLayoutGuideTop).inset(40);
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        
    }];
    
    [self xlscr];
    [KingdergartenSele addSubview:self.tableView];
    bigview = [[UIView alloc] initWithFrame:self.view.frame];
    bigview.backgroundColor = [UIColor blackColor];
    bigview.alpha = 0.3;
    [self.view addSubview:bigview];
    bigview.hidden = YES;
    [self KingdergartenSelect];
//    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.DataSoure.count*44) style:UITableViewStylePlain];
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) style:UITableViewStylePlain];
    if (self.DataSoure.count > 4) {
        self.tableView.frame = CGRectMake(0, 0, self.view.frame.size.width, 4*44);
    }else{
        self.tableView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.DataSoure.count*44);
    }
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.backgroundColor = [UIColor clearColor];
    [KingdergartenSele addSubview:self.tableView];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.DataSoure.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    cell.textLabel.text = self.DataSoure[indexPath.row];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.01;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *vivi = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 0.01)];
    vivi.backgroundColor = [UIColor clearColor];
    return vivi;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    KingdergartenSele.hidden = YES;
    bigview.hidden = YES;
    DropDownBtn.selected = NO;
}
- (void)KingdergartenSelect{
    DropDownBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 30)];
    [DropDownBtn setImage:[UIImage imageNamed:@"xiala"] forState:UIControlStateNormal];
    [DropDownBtn addTarget:self action:@selector(XiaLaBtn) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:DropDownBtn];
    [DropDownBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view.mas_safeAreaLayoutGuideTop).inset(40);
        make.right.mas_equalTo(-80);
        make.size.height.mas_equalTo(20);
        make.size.width.mas_equalTo(20);
    }];
    KingdergartenSele = [[UIView alloc] initWithFrame:CGRectMake(0, 74, 180, 180)];
    KingdergartenSele.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:KingdergartenSele];
    KingdergartenSele.layer.cornerRadius = 10;
    KingdergartenSele.layer.masksToBounds = YES;
    KingdergartenSele.hidden = YES;
//    DropDownBtn.selected = NO;
    [KingdergartenSele mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view.mas_safeAreaLayoutGuideTop).inset(74);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        if (self.DataSoure.count>4) {
            make.size.height.mas_equalTo(4*44+20);
        }else{
            make.size.height.mas_equalTo(self.DataSoure.count*44+20);
        }
        
    }];
}
-(UILabel *)HeaderText{
    _HeaderText = [[UILabel alloc] initWithFrame:CGRectMake((self.view.frame.size.width - 200) / 2, 40+44, 200, 18)];
    _HeaderText.text = @"xx幼儿园人工智能系统";
    _HeaderText.textAlignment = NSTextAlignmentCenter;
    //rgba(255/255.0, 255/255.0, 255/255.0, 1)
    _HeaderText.textColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1];
    _HeaderText.font = [UIFont systemFontOfSize:18];
    return _HeaderText;
}
- (void)xlscr{
    NSArray *TitlesArr = @[@"管理中心" , @"表情筛选推送" , @"班级语言汇总"];
    NSArray *ControllersArr = @[@"ManagementCenterViewController" , @"FaceFiltratePushViewController" , @"ClassLanguageCollectViewController"];
    NSMutableArray *ViewControllers = [[NSMutableArray alloc] init];
    for (int i = 0 ; i < TitlesArr.count; i ++) {
        //字符串创建控制器
        UIViewController *VC = [[NSClassFromString(ControllersArr[i])alloc] init];
        [ViewControllers addObject:VC];
    }
    //滚动视图
    _ScrollView = [[XLSlideSwitch alloc] initWithFrame:CGRectMake(0, 89+46, self.view.bounds.size.width, self.view.bounds.size.height - 86 - 40 - 90) Titles:TitlesArr viewControllers:ViewControllers];
    _ScrollView.delegate = self;
    _ScrollView.itemNormalColor = [UIColor whiteColor];
    _ScrollView.itemSelectedColor =[UIColor whiteColor];
    _ScrollView.customTitleSpacing = 30;
    [_ScrollView showInViewController:self];
    [_ScrollView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.size.height.mas_equalTo(self.view.frame.size.height-160);
        make.top.mas_equalTo(self.view.mas_safeAreaLayoutGuideTop).inset(90);
    }];
}
- (void)XiaLaBtn{
    if (DropDownBtn.selected == YES) {
        KingdergartenSele.hidden = YES;
        bigview.hidden = YES;
        DropDownBtn.selected = NO;
    }else{
        KingdergartenSele.hidden = NO;
        bigview.hidden = NO;
        DropDownBtn.selected = YES;
    }
}
@end
